import React from 'react';
import {Link, NavLink} from 'react-router-dom';

var $ = (function(){
  var ajax=function(url,callback){
       var xhr=new XMLHttpRequest();
       xhr.open("POST",url,true);
       xhr.send("");
       xhr.onreadystatechange=function(){
         if(xhr.readyState==4&&xhr.status==200){
               callback(JSON.parse(xhr.responseText));
         }
        }
  } 
  return {
    http:ajax    
   }
})();
export default class News extends React.Component{

              constructor(props) {
                super(props);                
            this.state={ 
              id:{
                id:0
              },
                data:{
                    data:[[{1:''}]]
                }
            }
            }
            componentWillMount(){
            var _this=this;
            var a=null;
            var arr=[];
            $.http(`http://10.31.160.25:3000/News/list/${this.props.match.params.id}`,function(data){
                    arr.push(data.docs)
                    _this.setState({
                        data: Object.assign({}, _this.state.data, {data:arr}),
                    })   
            });
            }
    render(){
      let list = [];
      let button=[];
    const {news} = this.state.data.data[0];
    const newsList = this.state.data.data[0].length;
    for(var i=0;i<newsList;i++){
        const Link='./News';
        if(this.state.data.data[0][i]._id===this.props.match.params.id){
            list.push(
                <p>{this.state.data.data[0][i].global}</p>,
                <p>{this.state.data.data[0][i].content}</p>
         )
      }
    }
    return(
          <div>   
               {list}
               {/* {button} */}
               
        </div>
        
        )
    }
  
};